package com.rui.study.algorithm.T_OutOfMemoryError;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-02-25 14:09
 **/
public class DirectMemory {

    private static final int _1MB = 1024 * 1024;

    public static void main(String[] args) {
        Field field = Unsafe.class.getDeclaredFields()[0];
        field.setAccessible(true);
        try {
            Unsafe unsafe = (Unsafe) field.get(null);
            while (true) {
                unsafe.allocateMemory(_1MB);
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
